/*
 * @Author: Otway
 * @Date: 2019-01-09 11:16:08
 * @LastEditors: Otway
 * @LastEditTime: 2019-08-30 18:50:09
 * @copyright: h-visions
 */
import React, { PureComponent } from 'react';
import {
    Row,
    Col,
    Form,
    Input,
    Select,
} from 'antd';
const FormItem = Form.Item;
const { Option } = Select
const formItemLayout = {
    // 抽屉里面Form。二列的布局比例
    labelCol: {
        span: 6
    },
    wrapperCol: {
        span: 18
    }
};
class AddFrom extends PureComponent {
    render() {
        const {
            formData,
            one,
            form: { getFieldDecorator },
        } = this.props;
        return (
            <Form >
                <Row>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'表单编码:'}>
                            {getFieldDecorator('code', {
                                initialValue: one ? formData.code : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '表单编码不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='请输入表单编码' allowClear />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'表单名称:'}>
                            {getFieldDecorator('name', {
                                initialValue: one ? formData.name : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '表单名称不能为空'
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='请输入表单名称' allowClear />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'类型:'}>
                            {getFieldDecorator('type', {
                                initialValue: one ? formData.type : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '请选择类型'
                                    }
                                ]
                            })(<Select allowClear={true} showSearch>
                                <Option value='试机' key={2}>试机</Option>
                                <Option value='自检' key={3}>自检</Option>
                                <Option value='质检' key={4}>质检</Option>
                            </Select>)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'适用对象:'}>
                            {getFieldDecorator('object', {
                                initialValue: one ? formData.object : undefined,
                                rules: [
                                    {
                                        required: true,
                                        message: '选择适用对象'
                                    }
                                ],
                            })(
                                <Select allowClear mode='multiple'>
                                    {
                                        this.props.returnModel[0] !== undefined && this.props.returnModel.map((value, index) => {
                                            return <Option value={value} key={index}>{value}</Option>
                                        })
                                    }
                                </Select>
                            )}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'备注:'}>
                            {getFieldDecorator('remark', {
                                initialValue: one ? formData.remark : null,
                                rules: [
                                    {
                                        required: false,
                                        message: ''
                                    }
                                ],
                                getValueFromEvent: (event) => {
                                    return event.target.value.replace(/\s+/g, "")
                                },
                            })(<Input placeholder='请输入备注' allowClear />)}
                        </FormItem>
                    </Col>
                    <Col span={24}>
                        <FormItem {...formItemLayout} label={'状态:'}>
                            {getFieldDecorator('isDelete', {
                                initialValue: one ? formData.isDelete : null,
                                rules: [
                                    {
                                        required: true,
                                        message: '请选择状态'
                                    }
                                ]
                            })(
                                <Select allowClear={true} showSearch>
                                    <Option value={0}>启动</Option>
                                    <Option value={1}>停止</Option>
                                </Select>
                            )}
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        );
    }
}

export default Form.create()(AddFrom);
